<?php /*
<?php if(!isset($default_feats)): ?>

<form method="POST" action="<?php echo url_for('test/openProject?id='.$annoset->getId()); ?> ">
<?php foreach($feats_lists as $layer_name=>$feats_types): ?>
<h2>Feats types for <?php echo $layer_name; ?> </h2>
	<?php foreach($feats_types as $feats_type=>$feats_names): ?>
	<h3>Choose a default feat for <?php echo $feats_type; ?> : </h3>
	<p>
		<?php $first = true; ?>
		<?php foreach($feats_names as $feat_name=>$feat_values): ?>
		<input type="radio" name="<?php echo $layer_name.'['.$feats_type.']'; ?>" value="<?php echo $feat_name; ?>" 
		<?php if($first === true): ?>
		<?php $first = false; ?>
		checked="checked"
		<?php endif; ?>
		 ><?php echo $feat_name; ?><br/>
		<?php endforeach; ?>
	</p>
	<?php endforeach; ?>
<?php endforeach; ?>
<p>
	<input type="submit" value="ok"/>
</p>
</form>

<?php else: ?>
//*/?>

<?php /*
			<?php
			use_javascript('renderer.js'); 
			use_javascript('toolTip.js');
			//use_javascript('displayLayer.js');
			use_javascript('editElement.js');
			//use_javascript('addDeleteElement.js');
			//use_javascript('editSelect.js');
			//use_javascript('editFeatDef.js');
			//use_javascript('Open.js');
			//use_javascript('importMediaProject.js');

			$marks_level = array();
			$structs_level = array(); 
			echo $annoset.'<br/>';
			/*foreach($structs as $struct)
			{
				$string = $struct->getId().'<br/>';
				echo $string;
			}//*/
/*			foreach($structs as $struct){
				$string = $struct->getId();
				/*if($mark->isToken())
					continue;//*/
/*				$id = $struct->getId();
				$element = Paula::getLevelTest($struct, $entities, $rels);
				/*if(!$sons) 
					$string .= ' no sons <br/>';
				else
					$string .= '<br/>';
				echo $string;//*/
/*				$level = $element['level'];
				$string = 'Level : '.$level.', id : '.$struct->getId().', PaulaId : '.$struct->getPaulaId().', AttId : '.$struct->getAttId().', List type : '.$struct->getListType()
					.', base : '.$struct->getBase().'<br/>';
				echo $string;//*/
/*			}//*/
			?>

<?php //endif; ?>


<?php /**************************************************************************************************/ ?>



<?php if(isset($default_feats)): ?>

<form method="POST" action="<?php echo url_for('test/index'); ?> ">
<?php foreach($feats_lists as $layer_name=>$feats_types): ?>
<h2>Feats types for <?php echo $layer_name; ?> </h2>
	<?php foreach($feats_types as $feats_type=>$feats_names): ?>
	<h3>Choose a default feat for <?php echo $feats_type; ?> : </h3>
	<p>
		<?php $first = true; ?>
		<?php foreach($feats_names as $feat_name=>$feat_values): ?>
		<input type="radio" name="<?php echo $layer_name.'['.$feats_type.']'; ?>" value="<?php echo $feat_name; ?>" 
		<?php if($first === true): ?>
		<?php $first = false; ?>
		checked="checked"
		<?php endif; ?>
		 ><?php echo $feat_name; ?><br/>
		<?php endforeach; ?>
	</p>
	<?php endforeach; ?>
<?php endforeach; ?>
<p>
	<input type="submit" value="ok"/>
</p>
</form>

<?php else: ?>




<?php
use_javascript('renderer.js'); 
use_javascript('toolTip.js');
//use_javascript('displayLayer.js');
use_javascript('editElement.js');
//use_javascript('addDeleteElement.js');
//use_javascript('editSelect.js');
//use_javascript('editFeatDef.js');
//use_javascript('Open.js');
//use_javascript('importMediaProject.js');

$marks_level = array();
$structs_level = array(); 
//print_r($default_feats);
?>



<script type="text/javascript" language="javascript">
if(getRenderer())
    getRenderer().destroy();
initDisplay('whiteboard');
var renderer = getRenderer();
var x_pos = 10; 
var y_pos = 70;
var x_max = 0;
var y_min = 0;
var y_max = 0;
var l = 0;
</script>


<?php foreach($marks as $mark): ?>
	<?php if($mark->isToken()): ?>
		<?php $text = $mark->getText(); ?>
		
		<script type="text/javascript" language="javascript">
		//var dx_pos = 0;
		//var dy_pos = 0;           
		rect = new Graphic.Rectangle(renderer); 
		rect.setFill({r: 204, g: 204, b: 205, a: 128});
		rect.setStroke({r: color[2]["r"], g: color[2]["g"], b: color[2]["b"], a: 255});
		rect.setRoundCorner(10, 10);
		rect.translate(x_pos, y_pos);
		rect.setID('<?php echo $mark->getAttId(); ?>');
	
		rect.setTextValue("<?php echo $text; ?>");
		rect.setTextColor(color[2]["r"],color[2]["g"],color[2]["b"]);
		size = rect.getSize();
		renderer.add(rect);//*/
		y_pos += size['h'] + 10;
		</script>
	
	<?php endif; ?>



	<?php
	$element = Paula::getLevelTest($mark, $entities, $rels);
	$level = $element['level'];
	$marks_level[$level][] = $element;
	?>
	
<?php endforeach; ?>
<?php ksort($marks_level); ?>



<?php foreach($marks as $mark): ?>
	<?php if(!$mark->isToken()): ?>
		<?php
		if(isset($feats_list[$mark->getPaulaId()], $feats_list[$mark->getPaulaId()][$mark->getAttId()]))
			$text = $feats_list[$mark->getPaulaId()][$mark->getAttId()]->current();
		else
			$text = $mark->getAttId();
		?>
		<script type="text/javascript" language="javascript">
		//var dx_pos = 0;
		//var dy_pos = 0;           
		rect = new Graphic.Rectangle(renderer); 
		rect.setFill({r: 204, g: 204, b: 205, a: 128});
		rect.setStroke({r: color[2]["r"], g: color[2]["g"], b: color[2]["b"], a: 255});
		rect.setRoundCorner(10, 10);
		rect.translate(x_pos, y_pos);
		rect.setID('<?php echo $mark->getAttId(); ?>');
	

		rect.setTextValue("<?php echo $text; ?>");
		rect.setTextColor(color[2]["r"],color[2]["g"],color[2]["b"]);
		size = rect.getSize();
		renderer.add(rect);//*/
		y_pos += size['h'] + 10;
		</script>
	<?php endif; ?>
<?php endforeach; ?>



<?php foreach($marks_level as $marks): ?>
<?php foreach($marks as $mark): ?>



	<?php if($mark['sons']): ?>
		<script>
			var first = true;
			rect = renderer.get("<?php echo $mark['element']->getAttId(); ?>");
		</script>
		<?php foreach ($mark['sons'] as $son): ?>
			<script>
			var rectTo = renderer.get("<?php echo $son['son']->getAttId(); ?>");
			if(first === true)
			{
				first = false;
				init_y_pos = rectTo.getMatrix()['dy'];
				y_min = init_y_pos;
				y_max = init_y_pos;
				x_max = rectTo.getMatrix()['dx'] + rectTo.getSize()['w'];		
			}
			end_y_pos = rectTo.getMatrix()['dy'];
			if(end_y_pos > y_max)
				y_max = end_y_pos;
			if((rectTo.getMatrix()['dx'] + rectTo.getSize()['w'])>x_max)
				x_max = rectTo.getMatrix()['dx'] + rectTo.getSize()['w']; 
      var line = new Graphic.Line(renderer); 
      line.setPoints(rect.getMatrix()["dx"]
      	, rect.getMatrix()["dy"]+rect.getSize()["h"]/2
      	, rectTo.getMatrix()["dx"]+rectTo.getSize()["w"]
      	, rectTo.getMatrix()["dy"]+rectTo.getSize()["h"]/2);
      line.setStroke({r: color[2]["r"], g: color[2]["g"], b: color[2]["b"], a: 128, w: 2});
      line.setID("l"+l)
      l +=1 ; 
      line.setFrom(rect.getID());
      line.setTo(rectTo.getID());
      rect.addLineFrom(line.getID(),rectTo.getID());
      rectTo.addLineTo(line.getID(),rect.getID());
      //line.hide();
      renderer.add(line);
      renderer.moveToBack(line);//*/
			</script>
		<?php endforeach; ?>
		<script>
		//rect.setPosition(x_pos + 100,(init_y_pos + end_y_pos)/2);
		rect.setPosition(x_max + 100,(y_min + y_max)/2);
		</script>
	<?php endif; ?>



<?php endforeach; ?>
<?php endforeach; ?>



<?php foreach($structs as $struct): ?>



	<?php if($struct->getListType() != 'annoSet'): ?>
	
		<?php
			if(isset($feats_list[$struct->getPaulaId()], $feats_list[$struct->getPaulaId()][$struct->getAttId()]))
				$text = $feats_list[$struct->getPaulaId()][$struct->getAttId()]->current();
			else
				$text = $struct->getAttId();
		?>
	
		<?php		
		$element = Paula::getLevelTest($struct, $entities, $rels);
		$level = $element['level'];
		$structs_level[$level][] = $element;
		?>
		

		
		<script type="text/javascript" language="javascript">
		var dx_pos = 0;
		var dy_pos = 0;               
		rect = new Graphic.Rectangle(renderer);
		
		
		rect.setFill({r: 204, g: 204, b: 205, a: 128});
		rect.setStroke({r: color[2]["r"], g: color[2]["g"], b: color[2]["b"], a: 255});
		rect.setRoundCorner(10, 10);
		rect.translate(x_pos, y_pos); 
		
		rect.setID("<?php echo $struct->getAttId(); ?>");
		
		rect.setTextValue("<?php echo $text; ?>");
		rect.setTextColor(color[2]["r"],color[2]["g"],color[2]["b"]);
		size = rect.getSize();
		renderer.add(rect);//*/
		y_pos += size['h'] + 10;
		</script>
		

		
	<?php endif; ?>


	
<?php endforeach; ?>
<?php ksort($structs_level); ?>



<?php foreach($structs_level as $structs): ?>
<?php foreach($structs as $struct): ?>
	<?php if($struct['sons']): ?>
		<?php $paula_id = $struct['element']->getPaulaId(); ?>
		<script>
			var first = true;
			rect = renderer.get("<?php echo $struct['element']->getAttId(); ?>");
		</script>
		<?php foreach ($struct['sons'] as $son): ?>
			<?php
			//$paula_id = $son['son']->getPaulaId();
			$rel_id = $son['rel_id'];
			if(isset($feats_list[$paula_id], $feats_list[$paula_id][$rel_id]))
				$link_text = $feats_list[$paula_id][$rel_id]->current();
			else
				$link_text = '';
			?>
			<script>
			var rectTo = renderer.get("<?php echo $son['son']->getAttId(); ?>");
			if(first === true)
			{
				first = false;
				init_y_pos = rectTo.getMatrix()['dy'];
				y_min = init_y_pos;
				y_max = init_y_pos;
				x_max = rectTo.getMatrix()['dx'] + rectTo.getSize()['w'];		
			}
			end_y_pos = rectTo.getMatrix()['dy'];
			if(end_y_pos > y_max)
				y_max = end_y_pos;
			if((rectTo.getMatrix()['dx'] + rectTo.getSize()['w'])>x_max)
				x_max = rectTo.getMatrix()['dx'] + rectTo.getSize()['w']; 
			
      var line = new Graphic.Line(renderer); 
      line.setPoints(rect.getMatrix()["dx"]
      	, rect.getMatrix()["dy"]+rect.getSize()["h"]/2
      	, rectTo.getMatrix()["dx"]+rectTo.getSize()["w"]
      	, rectTo.getMatrix()["dy"]+rectTo.getSize()["h"]/2);
      line.setStroke({r: color[2]["r"], g: color[2]["g"], b: color[2]["b"], a: 128, w: 2});
      line.setID("l"+l)
      l +=1 ; 
      line.setFrom(rect.getID());
      line.setTo(rectTo.getID());
      line.setText("<?php echo $link_text; ?>", color[2]["r"], color[2]["g"], color[2]["b"]);
      rect.addLineFrom(line.getID(),rectTo.getID());
      rectTo.addLineTo(line.getID(),rect.getID());
      //line.hide();
      renderer.add(line);
      renderer.moveToBack(line);//*/
			</script>
		<?php endforeach; ?>
		<script>
		rect.setPosition(x_max + 100,(y_min + y_max)/2);
		</script>
	<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>



<?php endif; ?>





